package com.gzsxy.esjy.bus.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzsxy.esjy.bus.dao.LoginlogMapper;
import com.gzsxy.esjy.bus.entity.LoginLogQueryVo;
import com.gzsxy.esjy.bus.service.LoginlogService;
import com.gzsxy.esjy.service.base.dto.request.LoginLogRequest;

import com.gzsxy.esjy.service.base.dto.response.PageResult;
import org.springframework.stereotype.Service;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 登录日志
 * @date 2022/5/3 18:54
 */
@Service
public class LoginlogServiceImpl extends ServiceImpl<LoginlogMapper, LoginLogRequest> implements LoginlogService {

    @Override
    public void addLoginlog(LoginLogRequest loginLogRequest) {
        baseMapper.insert(loginLogRequest);
    }


    /**
     * @description: 分页查询当前登录日志
     * @param
     * @return
     */
    @Override
    public PageResult<LoginLogRequest> getPageVo(IPage<LoginLogRequest> pageParam, LoginLogQueryVo loginLogQueryVo) {
        LambdaQueryWrapper<LoginLogRequest> wrapper = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(loginLogQueryVo.getUserName())){
            wrapper.eq(LoginLogRequest::getUserName,loginLogQueryVo.getUserName());
        }
        if (StringUtils.isNotBlank(loginLogQueryVo.getSchool())){
            wrapper.eq(LoginLogRequest::getSchool,loginLogQueryVo.getSchool());
        }
        wrapper.orderByDesc(LoginLogRequest::getLoginTime);
        IPage<LoginLogRequest> page = baseMapper.selectPage(pageParam, wrapper);
        PageResult<LoginLogRequest> pageResult = new PageResult<>();
        pageResult.setRecords(page.getRecords());
        pageResult.setTotal(page.getTotal());
        return pageResult;
    }
}
